How do you put an elephant on a containership in 3 steps?

Open Source Experience
2022-11-08

logo EDB

Who am I

Image by Anemone123 from Pixabay

Postgres on containers

  • What?
  • Why?
  • How?
  • Is this for me?
Image by Gerd Altmann from Pixabay
logo EDB

Containers are:

  • isolated
  • light weight
  • secured communications
  • an encapsulation of all softwares, configuration and librairies
Image by monicore from Pixabay
logo EDB

Several technologies

  • Docker
  • LXC (LinuX Containers)
  • Podman
  • ...
Image by Ulrike Leone from Pixabay
logo EDB

is that all?

  • No
  • It goes deeper
  • Here comes... Kubernetes!
Image by Design_Miss_C from Pixabay
logo EDB

Kubernetes

Kubernetes is an open-source container orchestration system for automating software deployment, scaling, and management.
Image by David Mark from Pixabay
logo EDB

Cloud Native PG

  • Postgres Kubernetes operator
  • Apache 2.0 license
  • In the CNCF sanbox

Why?

  • Who has standalone Postgres nowadays?
  • Who manages less than 5 clusters in production?

➜ More things to do, less administrators

Image by Ian Lindsay from Pixabay
logo EDB

DBA Tasks

  • Installations/Configurations
  • Securization
  • Backup policy implementation
  • HA policy implementation
  • Minor/Major upgrades
  • Monitoring
  • Troubleshooting
logo EDB
https://dbaday.org/
Image by Gerd Altmann from Pixabay

Changing scripting into configuration

  • installation/configurations
  • securization
  • Backup/HA implementation
  • Minor upgrades

And more!

  • Self-healing
  • Everything in one place
  • Service encapsulation
  • Self-service for devs

ACID

  • Atomicity
  • Consistency
  • Isolation
  • Durability

Stateless/statefull

The way containers are designed, and particularly the way Docker is designed, the assumption is that the container is stateless.
Mark Davis, ClusterHQ, 17 Jun 2015
Image by Niek Verlaan from Pixabay

Some tried early...

... And failed

It shouldn't be a reason not to try again!

Image by Esther Merbt from Pixabay

The key change

Kubernetes 1.14 and persistent volumes

Image by suju-foto from Pixabay

How?

  • Declare your configuration
  • Deploy
  • Relax
Image by 은주 송 from Pixabay

Simple

# Example of PostgreSQL cluster
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-example
spec:
  instances: 3

  storage:
    size: 1Gi
Image by 은주 송 from Pixabay

Specific Postgres version

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
   # [...]
spec:
   # [...]
   imageName: ghcr.io/cloudnative-pg/postgresql:13.6
   #[...]
Image by 은주 송 from Pixabay

Backups

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
# [...]
spec:
  backup:
    barmanObjectStore:
      destinationPath: "[destination path here]"
      s3Credentials:
        accessKeyId:
          name: aws-creds
          key: ACCESS_KEY_ID
        secretAccessKey:
          name: aws-creds
          key: ACCESS_SECRET_KEY
Image by 은주 송 from Pixabay

Settings

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
# [...]
spec:
  postgresql:
    parameters:
      shared_buffers: "1GB"
      auto_explain.log_min_duration: "10s"
    pg_hba:
      - host laetitia laetitia all scram-sha-256
  # [...]
Image by 은주 송 from Pixabay

Resources

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
# [...]
  resources:
    requests:
      memory: "32Mi"
      cpu: "50m"
    limits:
      memory: "128Mi"
      cpu: "100m"
  # [...]
Image by 은주 송 from Pixabay

Rolling upgrades

    Triggered when...
  • Changing the imageName
  • Changing PostgreSQL configuration that needs a restart
  • A change on resources
  • A change on PVC on AKS
  • after an operator update
Image by 은주 송 from Pixabay

Logs

  • CSV Format (on disk)
  • JSON format with kubectl logs
Image by 은주 송 from Pixabay

Is that for you?

It depends...

  • Is your team experimented with Kubernetes?
  • Is your team experimented with Postgres?
  • Do you manage more than 5 Postgres clusters?

Caution

Your Postgres database still needs

  • Data modeling
  • Correct SQL queries
  • Careful monitoring
Image by succo from Pixabay

Any questions?

Image by Andrew Martin from Pixabay